package com.example.powernodemall.controller;

import com.example.powernodemall.Util.GetSecurityUserUtil;
import com.example.powernodemall.entity.SysMenu;
import com.example.powernodemall.model.Result;
import com.example.powernodemall.model.SecurityUser;
import com.example.powernodemall.model.SysMenuPage;
import com.example.powernodemall.service.QuerySysMenuService;
import com.example.powernodemall.vo.MenuAndPermsVo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/sys/menu")
public class SysMenuController {
    @Resource
    QuerySysMenuService querySysMenuService;

    @GetMapping("/nav")
    public Result<MenuAndPermsVo> GetSysMenu() {
        //获取当前登录用户
        SecurityUser securityUser = GetSecurityUserUtil.getSecurityUser();
        //获取页面权限
        List<SysMenuPage> sysMenuSet=querySysMenuService.queryPageAuthrization(securityUser.getUserId());
        //获取用户权限
        Set<String> roles = securityUser.getRoles();
        return Result.Success(new MenuAndPermsVo(sysMenuSet,roles));
    }
}
